//
//  AppConfig.m
//  CardCat
//
//  Created by admin on 16/3/1.
//  Copyright (c) 2016年 haoniu. All rights reserved.
//

#import "AppConfig.h"
#import "HNPeopleInfo.h"
#import "JPUSHService.h"

@implementation AppConfig


#pragma -mark 沙盒操作
+(BOOL)saveUserInfo:(NSDictionary *)dic{
    if (dic) {
//                NSDictionary * _oldDic = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"UserInfo%@",_loginName]];
//                //NSUserDefaults支持的数据类型有：NSNumber（NSInteger、float、double），NSString，NSDate，NSArray，NSDictionary，BOOL.
//                //所以需要转换一下
//                _oldDic = dic;
        [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"UserInfo"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return true;
    }else{
        [[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"UserInfo"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return true;
    }
    return false;
}

+(BOOL)modifyUserInfoByDic:(NSDictionary *)dic{
    if (dic) {
        NSMutableDictionary * oldDic = [NSMutableDictionary dictionaryWithDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"UserInfo"]];
        if (oldDic && oldDic.count>0) {
            [oldDic addEntriesFromDictionary:dic];
            [[NSUserDefaults standardUserDefaults] setObject:oldDic forKey:@"UserInfo"];
        }else{
            [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"UserInfo"];
        }
    }
    [[NSUserDefaults standardUserDefaults] synchronize];
    return YES;
}

+(NSDictionary *)getUserInfo{
    NSDictionary * dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserInfo"];
    return dic;
}
+(NSString *)getUserInfoByKey:(NSString *)key{
    NSDictionary * dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserInfo"];
    if (dic && [dic objectForKey:key]) {
        return [dic objectForKey:key];
    }
    return nil;
}

+(BOOL)removeUserInfo{
    [[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"UserInfo"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return YES;
}

#pragma mark - 沙箱操作 之 用户信息存储

+(BOOL)addPersonInfo:(NSString *)goodsJsonStr{
    //存到用户数据库中
    NSDictionary *goodsDic = [AppConfig dictionaryWithJsonString:goodsJsonStr];
    NSLog(@"goodsDic = %@",goodsDic);
    NSDictionary *userInfo = [goodsDic objectForKey:@"member"];
    NSString *loginName = [NSString stringWithFormat:@"%@",[userInfo objectForKey:@"hnLoginName"]];
    if ([AppConfig isNULL:loginName]) {
        loginName = @"";
    }
    NSMutableDictionary *peopleDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:loginName,@"hnLoginName", nil];
    NSString *head = [NSString stringWithFormat:@"%@",[userInfo objectForKey:@"hnHead"]];
    if ([AppConfig isNULL:head]) {
        head = @"";
    }
    [peopleDic setObject:head forKey:@"hnHead"];
    NSString *nickName = [NSString stringWithFormat:@"%@",[userInfo objectForKey:@"hnNickName"]];
    if ([AppConfig isNULL:nickName]) {
        nickName = @"";
    }
    [peopleDic setObject:nickName forKey:@"hnNickName"];
    BOOL isSuccess = [AppConfig savePeopleInfo:peopleDic];
    if (!isSuccess) {
        NSLog(@"-------存储失败--------");
        return YES;
    }else{
        NSLog(@"-------存储成功--------");
        return NO;
    }
}

+(BOOL)savePeopleInfo:(NSDictionary *)peopleInfo{
    NSString *loginName = [peopleInfo objectForKey:@"hnLoginName"];
    NSLog(@"savePeopleInfo.loginName = %@",loginName);
    if (peopleInfo) {
           NSLog(@"0");
        [[NSUserDefaults standardUserDefaults] setObject:peopleInfo forKey:loginName];
        NSLog(@"1");
        [[NSUserDefaults standardUserDefaults] synchronize];
          NSLog(@"---end1---");
        return true;
    }else{
       [[NSUserDefaults standardUserDefaults] setObject:nil forKey:loginName];
        [[NSUserDefaults standardUserDefaults] synchronize];
          NSLog(@"---end2---");
        return true;
    }
}

+(NSDictionary *)getPeopleInfo:(NSString *)userLoginName{
    NSLog(@"start");
    NSDictionary * peopleInfo = [[NSUserDefaults standardUserDefaults] objectForKey:userLoginName];
       NSLog(@"end");
    return peopleInfo;
}


+(BOOL)removePeopleInfo:(NSString *)userLoginName{
    [[NSUserDefaults standardUserDefaults] setObject:nil forKey:userLoginName];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return YES;
}





//系统消息
+(BOOL)saveSystemMessageNum:(NSString *)smNum withUser:(NSString *)loginName{
    if (smNum) {
        [[NSUserDefaults standardUserDefaults] setObject:smNum forKey:[NSString stringWithFormat:@"SystemMessageNum_%@",loginName]];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return YES;
    }
    return NO;
}
+(NSString *)getSystemMessageNum:(NSString *)loginName{
    NSString * _smNum = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"SystemMessageNum_%@",loginName]];
    return _smNum;
}


+(BOOL)saveVersion:(NSString *)dic{
    if (dic == nil) {
        return NO;
    }
    [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"Version"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return YES;
}
+(NSString *)getVersion{
    NSString * dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"Version"];
    dic = dic==nil?@"":dic;
    return dic;
}

+(BOOL)saveHomePageData:(NSDictionary *)dic{
    if (dic == nil) {
        return NO;
    }
    [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"HomePageData"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return YES;
}
+(NSDictionary *)getHomePageData{
    NSDictionary * dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"HomePageData"];
    return dic;
}

//默认地址
+(BOOL)saveDefaultLocation:(NSDictionary *)dic{
    [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"DefaultLocation"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return YES;
}
+(NSDictionary *)getDefaultLocation{
    NSDictionary * dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"DefaultLocation"];
    return dic;
}

//默认地址
+(BOOL)saveLastLoginUserName:(NSString *)dic{
    [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"LastLoginUserName"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return YES;
}
+(NSString *)getLastLoginUserName{
    NSString * dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"LastLoginUserName"];
    return dic;
}

//通知设置
+(BOOL)saveNotification:(NSDictionary *)notifi{
    if (notifi) {
        [[NSUserDefaults standardUserDefaults] setObject:notifi forKey:@"NotificationSetting"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        return YES;
    }
    return NO;
}

+(NSDictionary *)getNotification{
    NSDictionary * notifi = [[NSUserDefaults standardUserDefaults] objectForKey:@"NotificationSetting"];
    return notifi;
}

#pragma mark - 操作plist
//根据键获取Tool文件中的value
+(NSString *)getStringByToolList:(NSString *)keyStr{
    if (keyStr && keyStr.length>0) {
        NSString *Tool = [[NSBundle mainBundle] pathForResource:@"UserConfigInfo" ofType:@"plist"];
        NSDictionary * _Dict = [[NSDictionary alloc]initWithContentsOfFile:Tool];
        NSString * _retStr = [_Dict objectForKey:keyStr];
        return _retStr;
    }else{
        return nil;
    }
}

//根据键获取UserConfigInfo文件中的value
+(NSString *)getStringByUserConfigInfo:(NSString *)keyStr{
    NSString * _retStr;
    if (keyStr && keyStr.length>0) {
        @try {
            NSString *Tool = [[NSBundle mainBundle] pathForResource:@"UserConfigInfo" ofType:@"plist"];
            NSDictionary * _Dict = [[NSDictionary alloc]initWithContentsOfFile:Tool];
            _retStr = [_Dict objectForKey:keyStr];
        }
        @catch (NSException *exception) {
            _retStr = nil;
        }
        return _retStr;
    }else{
        return nil;
    }
}
//根据键获取UserConfigInfo文件中的value
+(NSArray *)getArrayByUserConfigInfo:(NSString *)keyStr{
    if (keyStr && keyStr.length>0) {
        NSArray * _retStr;
        @try {
            NSString *Tool = [[NSBundle mainBundle] pathForResource:@"UserConfigInfo" ofType:@"plist"];
            NSDictionary * _Dict = [[NSDictionary alloc]initWithContentsOfFile:Tool];
            _retStr = [_Dict objectForKey:keyStr];
            if (!_retStr && _retStr.count==0) {
                _retStr = nil;
            }
        }
        @catch (NSException *exception) {
            _retStr = nil;
        }
        return _retStr;
    }else{
        return nil;
    }
}

//根据键设置UserConfigInfo文件中的value
+(void)setArrayByUserConfigInfo:(NSString *)keyStr withValue:(NSString *)valStr{
    if (keyStr && valStr) {
        @try {
            NSString *Tool = [[NSBundle mainBundle] pathForResource:@"UserConfigInfo" ofType:@"plist"];
            //NSDictionary * _Dict = [[NSDictionary alloc]initWithContentsOfFile:Tool];
            NSDictionary * param = [NSDictionary dictionaryWithObjectsAndKeys:valStr,keyStr, nil];
            [param writeToFile:Tool atomically:YES];
        }
        @catch (NSException *exception) {
            NSLog(@"＝＝读取配置文件出错");
        }
    }else{
        //return nil;
    }
}

//根据键获取UserConfigInfo文件中的value
+(NSDictionary *)getDictionaryByUserConfigInfo:(NSString *)keyStr{
    NSDictionary * _retStr;
    if (keyStr && keyStr.length>0) {
        @try {
            NSString *Tool = [[NSBundle mainBundle] pathForResource:@"UserConfigInfo" ofType:@"plist"];
            NSDictionary * _Dict = [[NSDictionary alloc]initWithContentsOfFile:Tool];
            _retStr = [_Dict objectForKey:keyStr];
            if (!_retStr || _retStr.count==0) {
                _retStr = nil;
            }
        }
        @catch (NSException *exception) {
            _retStr = nil;
        }
        return _retStr;
    }else{
        return nil;
    }
}


#pragma -mark 图片操作
//图片合并
+ (UIImage *)composeImage:(float)bili withImageBack:(UIImage *)imageBack withImage:(UIImage *)image{
//    float bl = bili>1?1:bili;
//    if (bl==1) {
//        return image;
//    }
    UIImage *img = image;
    CGImageRef imgRef = img.CGImage;
    CGFloat w = CGImageGetWidth(imgRef);
    CGFloat h = CGImageGetHeight(imgRef);
    
    CGRect rect = CGRectMake(0, 0, w*bili, h);
    CGImageRef cgimg = CGImageCreateWithImageInRect([img CGImage], rect);
    img = [UIImage imageWithCGImage:cgimg];
    imgRef = img.CGImage;
    w = CGImageGetWidth(imgRef);
    h = CGImageGetHeight(imgRef);
    
    //以1.png的图大小为底图
    UIImage *img1 = imageBack;
    CGImageRef imgRef1 = img1.CGImage;
    CGFloat w1 = CGImageGetWidth(imgRef1);
    CGFloat h1 = CGImageGetHeight(imgRef1);
    
    //以1.png的图大小为画布创建上下文
    UIGraphicsBeginImageContext(CGSizeMake(w1, h1));
    [img1 drawInRect:CGRectMake(0, 0, w1, h1)];//先把1.png 画到上下文中
    [img drawInRect:CGRectMake(0, 0, w, h)];//再把小图放在上下文中
    UIImage *resultImg = UIGraphicsGetImageFromCurrentImageContext();//从当前上下文中获得最终图片
    UIGraphicsEndImageContext();//关闭上下文
    //    CGImageRelease(imgRef);
    //    CGImageRelease(imgRef1);
    NSLog(@"=====:%d,%d,",(int)resultImg.size.width,(int)resultImg.size.height);
    return resultImg;
}
+(UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize withImage:(UIImage *)image
{
    UIImage *sourceImage = image;
    UIImage *newImage = nil;
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
    if (CGSizeEqualToSize(imageSize, targetSize) == NO)
    {
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;
        if (widthFactor > heightFactor)
            scaleFactor = widthFactor; // scale to fit height
        else
            scaleFactor = heightFactor; // scale to fit width
        scaledWidth= width * scaleFactor;
        scaledHeight = height * scaleFactor;
        // center the image
        if (widthFactor > heightFactor)
        {
            thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
        }
        else if (widthFactor < heightFactor)
        {
            thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
        }
    }
    UIGraphicsBeginImageContext(targetSize); // this will crop
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width= scaledWidth;
    thumbnailRect.size.height = scaledHeight;
    [sourceImage drawInRect:thumbnailRect];
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    if(newImage == nil)
        NSLog(@"could not scale image");
    //pop the context to get back to the default
    UIGraphicsEndImageContext();
    return newImage;
}
//剪裁图片，取中间部分(即：按照给定的值检查)
+(UIImage *)clippingImage:(UIImage *)image withWidth:(CGFloat)w withHeight:(CGFloat)h{
    CGFloat rectx = 0;
    CGFloat recty = 0;
    CGFloat rectw = image.size.width;
    CGFloat recth = image.size.height;
    if (w < rectw) {
        rectx = (rectw - w)/2;
        rectw = w;
    }
    if (h < recth) {
        recty = (recth - h)/2;
        recth = h;
    }
    CGRect rect = CGRectMake(rectx, recty, rectw, recth);
    CGImageRef cgimg = CGImageCreateWithImageInRect([image CGImage], rect);
    UIImage * retImg = [UIImage imageWithCGImage:cgimg];
    CGImageRelease(cgimg);
    return retImg;
}

//剪裁图片，按最大限度剪裁(即：按照给定的值检查)
+(UIImage *)clippingMaxImage:(UIImage *)image withWidth:(CGFloat)w withHeight:(CGFloat)h{
    //NSLog(@"=====clippingMaxImage:w:%f,h:%f",image.size.width,image.size.height);
    
    CGFloat imgW = image.size.width/w;
    CGFloat imgH = image.size.height/h;
    CGFloat rectx = 0;
    CGFloat recty = 0;
    CGFloat rectw = image.size.width;
    CGFloat recth = image.size.height;
    if (imgW <= imgH) {
        recty = (recth - h*imgW)/2;
        recth = h*imgW;
    }else{
        rectx = (rectw - w*imgH)/2;
        rectw = w*imgH;
    }
    CGRect rect = CGRectMake(rectx, recty, rectw, recth);
    CGImageRef cgimg = CGImageCreateWithImageInRect([image CGImage], rect);
    UIImage * retImg = [UIImage imageWithCGImage:cgimg];
    CGImageRelease(cgimg);
    return retImg;
}
//判断缓存中有没有有就读取缓存，否则下载
+(UIImage *)getImageExsit:(NSString *)urlPath{
    if (!urlPath || urlPath.length==0) {
        return nil;
    }
    NSString * imgName = [[urlPath componentsSeparatedByString:@"/"] lastObject];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:imgName];   // 保存文件的名称
    UIImage * img = [UIImage imageWithContentsOfFile:filePath];
    return img;
}
//判断缓存中有没有有就读取缓存，否则下载
+(UIImage *)getImageByURL:(NSString *)urlPath{
    if (!urlPath || urlPath.length==0) {
        return nil;
    }
    NSString * imgName = [[urlPath componentsSeparatedByString:@"/"] lastObject];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:imgName];   // 保存文件的名称
    NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlPath]];
    UIImage * img = [UIImage imageWithData:data];
    [UIImagePNGRepresentation(img)writeToFile:filePath atomically:YES];
    
    return img;
}
//判断缓存中有没有有就读取缓存，否则下载
+(UIImage *)getImageByURL:(NSString *)urlPath withW:(CGFloat)w withH:(CGFloat)h{
    if (!urlPath || urlPath.length==0) {
        return nil;
    }
    NSString * imgName = [[urlPath componentsSeparatedByString:@"/"] lastObject];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:imgName];   // 保存文件的名称
    NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlPath]];
    UIImage * img = [UIImage imageWithData:data];
    if (img != nil) {
        img = [self clippingImage:img withWidth:w withHeight:h];
    }
    [UIImagePNGRepresentation(img)writeToFile:filePath atomically:YES];
    
    return img;
}

//判断缓存中有没有有就读取缓存，否则下载
+(UIImage *)getImageByURLAndExsit:(NSString *)urlPath{
    if (!urlPath || urlPath.length==0) {
        return nil;
    }
    NSString * imgName = [[urlPath componentsSeparatedByString:@"/"] lastObject];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:imgName];   // 保存文件的名称
    UIImage * img = [UIImage imageWithContentsOfFile:filePath];
    if (img==nil) {
        NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlPath]];
        img = [UIImage imageWithData:data];
        [UIImagePNGRepresentation(img)writeToFile:filePath atomically:YES];
    }
    return img;
}

#pragma -mark 设置颜色
+ (UIColor *)colorWithHexString:(NSString *)color alpha:(CGFloat)alpha
{
    //删除字符串中的空格
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    // String should be 6 or 8 characters
    if ([cString length] < 6)
    {
        return [UIColor clearColor];
    }
    // strip 0X if it appears
    //如果是0x开头的，那么截取字符串，字符串从索引为2的位置开始，一直到末尾
    if ([cString hasPrefix:@"0X"])
    {
        cString = [cString substringFromIndex:2];
    }
    //如果是#开头的，那么截取字符串，字符串从索引为1的位置开始，一直到末尾
    if ([cString hasPrefix:@"#"])
    {
        cString = [cString substringFromIndex:1];
    }
    if ([cString length] != 6)
    {
        return [UIColor clearColor];
    }
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    //r
    NSString *rString = [cString substringWithRange:range];
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    return [UIColor colorWithRed:((float)r / 255.0f) green:((float)g / 255.0f) blue:((float)b / 255.0f) alpha:alpha];
}

//默认alpha值为1
+ (UIColor *)colorWithHexString:(NSString *)color
{
    return [self colorWithHexString:color alpha:1.0f];
}


#pragma -mark 字符串转化
//根据Json字符串返回Dictionary
+(NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    
    if (jsonString == nil) {
        return nil;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}
//根据Json字符串返回NSArray
+(NSArray *)ArrayWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSArray *arr = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return arr;
}
//根据Dictionary字符串返回Json
+(NSString*)dictionaryToJson:(NSDictionary *)dic{
    
    NSError *parseError = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
    if (parseError) {
        return nil;
    }
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
//根据Dictionary字符串返回Json
+(NSString*)arrayToJson:(NSArray *)arr{
    
    NSError *parseError = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:&parseError];
    if (parseError) {
        return nil;
    }
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}


+(MJRefreshGifHeader *)getCustomMJRefreshGifHeader{
    MJRefreshGifHeader *header = [[MJRefreshGifHeader alloc]init];
    NSMutableArray * imgs = [[NSMutableArray alloc]init];
    for (int i = 1; i<6; i++) {
        UIImage * img = [UIImage imageNamed:[NSString stringWithFormat:@"animation%d",i]];
        [imgs addObject:img];
    }
    [header setImages:imgs forState:MJRefreshStateIdle];
    [header setImages:imgs forState:MJRefreshStatePulling];
    [header setImages:imgs forState:MJRefreshStateRefreshing];
    return header;
}


#pragma -mark 判断字符串是否是空
+(BOOL)isNULL:(NSString *)inputStr{
    if (inputStr.length == 0 || [inputStr isEqualToString:@"<null>"]  || [inputStr isEqualToString:@"null"]  || [inputStr isEqualToString:@"(null)"]) {
        return 1;
    }else{
        return 0;
    }
}

+(BOOL)isStrNull:(NSString *)inputStr{
    if (inputStr.length == 0 || [inputStr isEqualToString:@"<null>"]  || [inputStr isEqualToString:@"null"]  || [inputStr isEqualToString:@"(null)"]) {
        return 1;
    }else{
        return 0;
    }
}


#pragma -mark 判断字符串是否是空
+(BOOL)isNULLObject:(id)object{
    if ([object isEqual:[NSNull null]]) {
        return YES;
    }else if ([object isKindOfClass:[NSNull class]]){
        return YES;
    }else if(object == nil){
        return YES;
    }
    return NO;
}

+(void)setTags:(NSMutableSet *)tags andAlias:(NSString *)alias{
    
    [JPUSHService setTags:tags alias:alias fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
        NSLog(@"rescode: %d, \ntags: %@, \nalias: %@\n", iResCode, iTags, iAlias);
        
        
    }];
    
}

//取消tag或者alias
+(void)cancelTags:(BOOL)cancelTags andcancelAlias:(BOOL)cancelAlias{
    if (cancelTags) {
        [self setTags:[NSMutableSet new] andAlias:nil];
    }
    if (cancelAlias) {
        [self setTags:nil andAlias:@""];
    }
}


+(UIImage*) createImageWithColor:(UIColor*) color
{
    CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}



@end
